package com.great.baseadapter;
import java.util.ArrayList;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
public class MyBaseAdapter extends BaseAdapter {
private Context context;
private ArrayList<MyData> list;
private MyData data;
private ViewHolder holder;
public MyBaseAdapter(Context context, ArrayList<MyData> list) {
super();
this.context = context;
this.list = list;
}
//返回条目数
@Override
public int getCount() {
return list.size();
}
//得到某一条目
@Override
public Object getItem(int position) {
return list.get(position);
}
//返回条目值
@Override
public long getItemId(int position) {
return position;
}
//进行适配
@Override
public View getView(int position, View convertView, ViewGroup parent) {
TextView tv_01 = null,tv_02=null;
//产生View
if(convertView==null)
{
convertView = LayoutInflater.from(context).inflate(R.layout.actvity_item, null);
holder = new ViewHolder();
holder.tv_01 = (TextView) convertView.findViewById(R.id.tv_01);
holder.tv_02 = (TextView) convertView.findViewById(R.id.tv_02);
//tv_01.setText(list.get(position).getText1());
//tv_02.setText(list.get(position).getText2());
convertView.setTag(holder);
}
else
{
holder = (ViewHolder) convertView.getTag();
// tv_01 = (TextView) convertView.findViewById(R.id.tv_01);
// tv_02 = (TextView) convertView.findViewById(R.id.tv_02);
//
// tv_01.setText(list.get(position).getText1());
// tv_02.setText(list.get(position).getText2());
}
holder.tv_01.setText(list.get(position).getText1());
holder.tv_02.setText(list.get(position).getText2());
return convertView;
}
private class ViewHolder
{
private TextView tv_01;
private TextView tv_02;
}
}
评论